//#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

//using namespace std;

typedef struct _list_node_s {
    int data;
    struct _list_node_s *next;
}list_node_t;

list_node_t *CreateList(int n)
{
    if (n <= 0)
        return NULL;
    list_node_t *_newList = NULL, *_tmp = NULL, *tmp = NULL;
    while (n--) {
        if (_newList==NULL) {
            _newList = (list_node_t*)malloc(sizeof(list_node_t));
            if (_newList) {
                _newList->data = n;
                _newList->next = NULL;
                _tmp = _newList;
            } else 
                break;
       } else {
           tmp = (list_node_t*)malloc(sizeof(list_node_t));
           _newList->next = tmp;
           _newList = tmp;
           if (_newList) {
                _newList->data = n;
            } else
                break;
       }
    }
    return _tmp;
}

void DisplayList(list_node_t *list, int n) 
{
    list_node_t *tmp = list;
    while (n--&&tmp) {
        printf("%d ", tmp->data);
        tmp = tmp->next;
    }
}

int main(int argc, const char *argv[])
{
    list_node_t *m_list;
    int n;
    int k;
    scanf("%d", &n);
    m_list = CreateList(n);
    DisplayList(m_list, n);
    printf("\n");
    scanf("%d", &k);
    
    list_node_t *tmp = NULL, *cur_idx = NULL;
    list_node_t *header, *tail, *g_header, *_tail;
    int _k, i, j = 0;

    cur_idx = m_list;
    while ((j-1 < n) && cur_idx) {
        tail = header = cur_idx;
        tmp = cur_idx->next;
        for (i = 0; (i < k-1) && tmp; i++) {
            cur_idx = tmp->next;
        
            tmp->next = header;
            header = tmp;

            tmp = cur_idx;
        }

        if (!j)
            g_header = header;
        j+=k;
        if (_tail)
            _tail->next = header;
        _tail = tail;
    }
    
    DisplayList(g_header, n);
    printf("\n");
    return 0;
}
